#include <nvboard.h>
#include "Vtop.h"
#include "verilated_fst_c.h"
#include "verilated.h"

Vtop* dut;
VerilatedContext* contextp = NULL;
VerilatedFstC* tfp = NULL;

void nvboard_bind_all_pins(Vtop* top);

static void single_cycle() {
  dut->clk = 0; dut->eval();
  dut->clk = 1; dut->eval();
}

static void reset(int n) {
  dut->rst = 1;
  while (n -- > 0) single_cycle();
  dut->rst = 0;
}

int main(int argc, char** argv) {
    contextp = new VerilatedContext;
    tfp = new VerilatedFstC;
    Verilated::traceEverOn(true);
    contextp->commandArgs(argc, argv);
    // logs
    Verilated::mkdir("logs");    
    dut = new Vtop();
    // nvboard setting
	nvboard_bind_all_pins(dut);
	nvboard_init();
	reset(10);
	while(1){
	  contextp->timeInc(1);
		nvboard_update();
		single_cycle();
	}
/*        Vtop* top = new Vtop{contextp};
    while (!contextp->gotFinish()) {
	contextp->timeInc(1);
	int a = rand() & 1;
	int b =  rand() & 1;
	top->a = a;
	top->b = b;
	top->eval();
	printf("a = %d, b = %d, f = %d\n", a, b, top->f);
	assert(top->f == (a^b));
    }
    delete top;
*/
    delete contextp;
    delete dut;
    return 0;
}
